/**
 * 作者: lipengfei
 * 日期: 2021-12-23 19:43:51
 * 备注: 充值礼包表
 */
package com.motu.monstercity.module.common.iap;

import com.motu.monstercity.module.common.utility.ServerParam;
import com.motu.vertx.module.utility.toolset.Tool;
import io.vertx.core.json.JsonObject;

import java.util.concurrent.ConcurrentHashMap;

public class IapGift extends IapGiftModel {

    // 充值参数的key
    public static final String PARAM_KEY_PRESENT_FIRST = "present_first"; // 元宝充值首充赠送

    // 礼包类型
    public static final int TYPE_DIAMOND_CHARGE = 1; // 元宝充值
    public static final int TYPE_DAY = 2; // 日礼包
    public static final int TYPE_WEEK = 3; // 周礼包
    public static final int TYPE_MONTH = 4; // 月礼包
    public static final int TYPE_GROWTH_FUND = 6; // 成长基金
    public static final int TYPE_PRIVILEGE_CARD = 7; // 特权卡礼包
    public static final int TYPE_VIP = 8; // VIP礼包
    public static final int TYPE_PUSH = 10; // 推送礼包
    public static final int TYPE_FIRST_CHARGE = 11; // 三日首冲礼包
    public static final int TYPE_RECHARGE_ACT_DAILY_SPECIAL_OFFER = 12; // 限时充值 每日特惠
    public static final int TYPE_RECHARGE_ACT_NORMAL = 13; // 限时充值 常规礼包
    public static final int TYPE_RECHARGE_ACT_RANKACT = 14; // 限时充值 冲榜礼包
    public static final int TYPE_BENEFIT_AD_GIFT = 16; // 广告连锁礼包 每日放映
    public static final int TYPE_ACT_CONVENTION_GIFT = 17; // 万能活动礼包
    public static final int TYPE_ACT_DISCOUNT_GIFT = 18; // 折扣礼包
    public static final int TYPE_UNION_SCUFFLE_GIFT = 19; // 联盟乱斗礼包
    public static final int TYPE_UNION_SCUFFLE_PASS = 20; // 联盟乱斗通行证
    public static final int[] RANKACT_RECHARGE_GIFTS = {TYPE_RECHARGE_ACT_NORMAL,
            TYPE_RECHARGE_ACT_RANKACT}; // 限时类礼包
    public static final int TYPE_ACT_DAILY_PASS = 21; // 高级补给礼包
    public static final int[] AD_GIFTS = {TYPE_DAY,TYPE_WEEK,TYPE_MONTH,TYPE_RECHARGE_ACT_DAILY_SPECIAL_OFFER,TYPE_RECHARGE_ACT_RANKACT,TYPE_BENEFIT_AD_GIFT}; // 限时类礼包  现实特惠 限时冲榜 游戏商城礼包
//    public static final int TYPE_FUND_MONTHLY = 9; // 基金月卡
//    public static final int TYPE_MOTIF_RECRUIT = 12; // 星愿召唤礼包
//    public static final int TYPE_MOTIF_EXCLUSIVE = 13; // 尊享礼包
//    public static final int TYPE_MOTIF_SUIT = 15; // 主题活动的时装礼包
//    public static final int TYPE_EXPERIENCE = 16; // 经验药水礼包
//    public static final int TYPE_FIRST_CHARGE_ACT = 17; // 每日首充活动礼包
//    public static final int TYPE_SUIT = 18; // 时装礼包
//    public static final int TYPE_LIMIT_SALE = 19; // 限时售卖礼包
//    public static final int TYPE_MOTIF_NEW_UP_STAR = 20; // 新英雄升星活动礼包
//    public static final int TYPE_MINE = 21; // 挖矿礼包
//    public static final int TYPE_FESTIVAL_FIGHT_GIFT = 22; // 节日活动战令礼包
//    public static final int TYPE_FESTIVAL_GIFT = 23; // 节日活动礼包贩卖
//    public static final int TYPE_FESTIVAL_OPEN_BOX_GIFT = 24; // 节日活动 开宝箱集字礼包
//    public static final int TYPE_BACK_ONE_YUAN_GIFT = 25; // 回归活动一元豪礼
//    public static final int TYPE_SELECT_GIFT = 26; // 自选礼包
//    public static final int TYPE_FISH = 27; // 钓鱼礼包
//    public static final int TYPE_CONTINUED_GIFT = 28; // 主题活动连续充值礼包
//    public static final int TYPE_MOTIF_SELECT_UP_STAR = 29; // 自选升星活动礼包
//    public static final int TYPE_FESTIVAL_DRAW = 30; // 节日活动扭蛋机礼包
//    public static final int TYPE_FESTIVAL_PLUNDER = 31; // 节日活动源石争夺战礼包
//    public static final int TYPE_FESTIVAL_FISH = 32; // 节日活动钓鱼活动礼包
//    public static final int TYPE_MOTIF_UP_DRAW = 33; // 限时召唤礼包
//    public static final int TYPE_MOTIF_GOLD_DRAW_REWARD = 34; // 主题活动次数奖励礼包
    public static final int TYPE_WEB_RECHARGE = 35; // 网页充值礼包
//    public static final int TYPE_MOTIF_GOLD_DRAW = 37; // 主题活动异界缔约礼包
//    public static final int TYPE_MULTIPLE_GIFT = 38; // 多个子活动类型生效的礼包
//    public static final int TYPE_FESTIVAL_NEW_FIGHT_GIFT = 39; // 节日活动新战令礼包
//    public static final int TYPE_FESTIVAL_PRIVILEGE = 40; // 节日活动特权活动礼包
//    public static final int TYPE_FESTIVAL_SUIT_COMEBACK = 41; // 节日活动时装返场活动礼包
//    public static final int TYPE_GUARD_DRAW = 42; // 侍魂抽卡礼包
//    public static final int TYPE_GUARD_BOSS_FIGHT_GIFT = 43; // 侍魂副本战令礼包
//    public static final int TYPE_GUARD_RUNE = 44; // 侍魂契印礼包
//    public static final int TYPE_SEASON_DUNGEON_EXPLORE = 45; // 赛季副本探索礼包
//    public static final int TYPE_SEASON_DUNGEON_FIGHT_GIFT = 46; // 赛季副本战令礼包
//    public static final int TYPE_MOTIF_OFFER_TASK = 47; // 主题活动悬赏任务礼包
//    public static final int TYPE_MOTIF_NPC = 48; // npc小人礼包
//    public static final int TYPE_MOTIF_SMALL_GIFT = 49; // 主题活动小额充值礼包
//    public static final int TYPE_AWAKENED_COMMANDER_SKILL = 50;// 神觉殿统帅技

    // 限制类型
    public static final int LIMIT_TYPE_DAY = 1; // 日重置
    public static final int LIMIT_TYPE_WEEK = 2; // 周重置
    public static final int LIMIT_TYPE_MONTH = 3; // 月重置
    public static final int LIMIT_TYPE_CUSTOM = 4; // 自定义时间

    // 礼包id
    public static final int ID_FUND_MONTHLY1 = 500; // 基金月卡1
    public static final int ID_FIGHT_GIFT = 600; // 战令礼包
    public static final int ID_CUT_GRASS_FIGHT_GIFT = 601; // 虚空幻境战令礼包
    public static final int ID_VESTIGE_FIGHT_GIFT = 602; // 失落遗迹战令礼包
    public static final int ID_PRIVILEGE_DISPATCH = 700; // 悬赏特权
    public static final int ID_PRIVILEGE_DRAW = 701; // 魔晶特权
    public static final int ID_PRIVILEGE_FAST_BATTLE = 702; // 作战特权
    public static final int ID_PRIVILEGE_SPIRITS = 703; // 秘灵特权
    public static final int ID_PRIVILEGE_HOLY_WEAPON = 704; // 圣武特权
    public static final int ID_PRIVILEGE_GUARD = 705; // 侍魂特权
    public static final int ID_PRIVILEGE_DIAMONDTRIALS = 706; // 钻石秘境特权
    public static final int[] ID_PRIVILEGE_SEASON_DUNGEON = {711,719}; // 赛季副本特权,特权的id段是711~719
    public static final int[] ID_PRIVILEGE_TRIAL_TOWER = {760,769}; // 试练塔活动特权,特权的id段是760~769

    public static final int ID_UNION_SCUFFLE_PASS_HIGH = 800; // 联盟乱斗进阶通行证
    public static final int ID_UNION_SCUFFLE_PASS_SPECIAL = 801; // 联盟乱斗专项通行证

    public static final byte YES = 1;

    public JsonObject params = new JsonObject(); // 充值参数
    private long[] rewardArray = new long[]{};
    public ConcurrentHashMap<Integer, Long> rewardMap = new ConcurrentHashMap<>();
    private int[] limitLevelAry = new int[]{};
    private JsonObject areaIapIdObj = new JsonObject();// 根据地区代码配置覆盖iapId

    public IapGift(JsonObject obj) {
        super(obj);
        if (!Tool.isEmpty(param)) {
            params = new JsonObject(param);
        }
        if (!Tool.isEmpty(reward)) {
            String[] strAry = reward.replace(" ", "").split(";");// 去除空格
            if (strAry.length >= 2) {
//                for (int i = 0; i < strAry.length; i += 2) {
//                    int itemId = Integer.parseInt(strAry[i]);
//                    long itemNum = Long.parseLong(strAry[i + 1]);
//                    if (itemId > 0 && itemNum > 0) {
//                        if (rewardMap.containsKey(itemId)) {
//                            rewardMap.put(itemId, rewardMap.get(itemId) + itemNum);
//                        } else {
//                            rewardMap.put(itemId, itemNum);
//                        }
//                    }
//                }
                rewardArray = new long[strAry.length];
                for (int i = 0; i < strAry.length; i++) {
                    rewardArray[i] = Long.parseLong(strAry[i]);
                }
            }
        }
        if (!Tool.isEmpty(limitLevel)) {
            limitLevelAry = Tool.strToIntArray(limitLevel, ";");
        }
        if (!Tool.isEmpty(getAreaIapId())) {
            areaIapIdObj = new JsonObject(getAreaIapId());
            this.getIapId();// 先执行一次，使部分异常在初始化的时候就能发现
        }
    }

    public JsonObject getParams() {
        return params;
    }

    public long[] getRewardArray() {
        return rewardArray;
    }

//    public ConcurrentHashMap<Integer, Long> getRewardMap() {
//        return rewardMap;
//    }

    public int[] getLimitLevelAry() {
        return limitLevelAry;
    }

    @Override
    public int getIapId() {
        if (Tool.isEmpty(ServerParam.IAP_AREA_MARK)) {
            return super.getIapId();
        }
        return areaIapIdObj.getInteger(ServerParam.IAP_AREA_MARK, super.getIapId());
    }

    /**
     * @return {"区域码":替换的IapId}
     */
    public JsonObject getAreaIapIdObj() {
        return areaIapIdObj;
    }

    /**
     * 是否是活动礼包
     */
//    public boolean isActIapGift() {
//        // 新人礼包、超值周卡礼包、星愿召唤礼包、尊享礼包、主题活动的时装礼包、限时售卖礼包、新英雄升星活动礼包、节日战令礼包
//        // 自选升星活动礼包、扭蛋机、节日活动钓鱼活动礼包、限时召唤礼包、主题活动悬赏任务礼包
//        if (type == TYPE_MOTIF_RECRUIT
//                || type == TYPE_MOTIF_EXCLUSIVE
//                || type == TYPE_MOTIF_SUIT
//                || type == TYPE_LIMIT_SALE
//                || type == TYPE_MOTIF_NEW_UP_STAR
//                || type == TYPE_FESTIVAL_FIGHT_GIFT
//                || type == TYPE_FESTIVAL_GIFT
//                || type == TYPE_FESTIVAL_OPEN_BOX_GIFT
//                || type == TYPE_BACK_ONE_YUAN_GIFT
//                || type == TYPE_SELECT_GIFT
//                || type == TYPE_CONTINUED_GIFT
//                || type == TYPE_MOTIF_SELECT_UP_STAR
//                || type == TYPE_FESTIVAL_DRAW
//                || type == TYPE_FESTIVAL_FISH
//                || type == TYPE_MOTIF_UP_DRAW
//                || type == TYPE_FESTIVAL_PLUNDER
//                || type == TYPE_MOTIF_GOLD_DRAW
//                || type == TYPE_MOTIF_GOLD_DRAW_REWARD
//                || type == TYPE_MULTIPLE_GIFT
//                || type == TYPE_FESTIVAL_NEW_FIGHT_GIFT
//                || type == TYPE_FESTIVAL_PRIVILEGE
//                || type == TYPE_FESTIVAL_SUIT_COMEBACK
//                || type == TYPE_MOTIF_OFFER_TASK
//                || type == TYPE_MOTIF_NPC
//                || type == TYPE_MOTIF_SMALL_GIFT) {
//            return true;
//        }
//        return false;
//    }

    /**
     * 是否赛季副本特权礼包
     */
    public boolean isSeasonDungeonPrivilege() {
        return this.getId() >= ID_PRIVILEGE_SEASON_DUNGEON[0] && this.getId() <= ID_PRIVILEGE_SEASON_DUNGEON[1];
    }

    /**
     * 是否是试练塔活动特权礼包
     */
    public boolean isTrialTowerPrivilege() {
        return this.getId() >= ID_PRIVILEGE_TRIAL_TOWER[0] && this.getId() <= ID_PRIVILEGE_TRIAL_TOWER[1];
    }

}
